<template>
  <div class="systemset-config-container">
    <el-card shadow="never">
      <el-form :model="from">
        <el-divider content-position="left">基础设置</el-divider>
        <el-form-item label-width="200" label="钉钉ClientID">
          <el-input
            v-model="from.base.DingClientID"
            type="password"
            style="width: 380px"
          />
        </el-form-item>
        <el-form-item label-width="200" label="钉钉密钥">
          <el-input
            v-model="from.base.DingClientSecret"
            type="password"
            style="width: 580px"
          />
        </el-form-item>
        <el-divider content-position="left">商机流出设置</el-divider>
        <el-form-item label-width="200" label="多少天未跟进小记提醒">
          <el-input
            v-model="from.business.BusinessWarning"
            style="width: 80px"
          />
          <span style="margin-left: 10px">天</span>
        </el-form-item>
        <el-form-item label-width="200" label="公海多少天不跟进流出">
          <el-input
            v-model="from.business.BusinessOpenSeaNoTrackOut"
            style="width: 80px"
          />
          <span style="margin-left: 10px; margin-right: 10px">天</span>
          <el-switch
            v-if="isData"
            v-model="from.business.isBusinessOpenSeaNoTrackOut"
            class="mt-2"
            inline-prompt
            :active-value="1"
            :inactive-value="0"
            :active-icon="Check"
            :inactive-icon="Close"
            @change="saveConfigSet"
          />
        </el-form-item>
        <el-form-item label-width="200" label="内海多少天不跟进流出">
          <el-input
            v-model="from.business.BusinessInSeaNoTrackOut"
            style="width: 80px"
          />
          <span style="margin-left: 10px; margin-right: 10px">天</span>
          <el-switch
            v-if="isData"
            v-model="from.business.isBusinessInSeaNoTrackOut"
            class="mt-2"
            inline-prompt
            :active-value="1"
            :inactive-value="0"
            :active-icon="Check"
            :inactive-icon="Close"
            @change="saveConfigSet"
          />
        </el-form-item>
        <el-form-item label-width="200" label="多少天未签约流出预警">
          <el-input
            v-model="from.business.BusinessOutWarning"
            style="width: 80px"
          />
          <span style="margin-left: 10px">天</span>
        </el-form-item>
        <el-form-item label-width="200" label="多少天未签约流出">
          <el-input
            v-model="from.business.BusinessNoSignOut"
            style="width: 80px"
          />
          <span style="margin-left: 10px; margin-right: 10px">天</span>
          <el-switch
            v-if="isData"
            v-model="from.business.isBusinessNoSignOut"
            class="mt-2"
            inline-prompt
            :active-value="1"
            :inactive-value="0"
            :active-icon="Check"
            :inactive-icon="Close"
            @change="saveConfigSet"
          />
        </el-form-item>
        <el-form-item label-width="200" label="已签约状态多少天未录单流出">
          <el-input
            v-model="from.business.SignNoInputDays"
            style="width: 80px"
          />
          <span style="margin-left: 10px; margin-right: 10px">天</span>
          <el-switch
            v-if="isData"
            v-model="from.business.isBusinessSignNoInput"
            class="mt-2"
            inline-prompt
            :active-value="1"
            :inactive-value="0"
            :active-icon="Check"
            :inactive-icon="Close"
            @change="saveConfigSet"
          />
        </el-form-item>
        <el-form-item label-width="200" label="商机人个原因出库多少天不能挑入">
          <el-input
            v-model="from.business.BusinessOutNoPick"
            style="width: 80px"
          />
          <span style="margin-left: 10px">天</span>
        </el-form-item>
        <!-- <el-form-item label-width="200" label="公海未签商机库容">
          <el-input
            v-model="from.business.BusinessOpenSeaNoSignNum"
            style="width: 80px"
          />
          <span style="margin-left: 10px">个</span>
        </el-form-item>
        <el-form-item label-width="200" label="内海未签商机库容">
          <el-input
            v-model="from.business.BusinessInSeaNoSignNum"
            style="width: 80px"
          />
          <span style="margin-left: 10px">个</span>
        </el-form-item> -->
        <el-form-item label-width="200">
          <el-button type="primary" @click="saveConfigSet">保存设置</el-button>
        </el-form-item>
      </el-form>
    </el-card>
  </div>
</template>

<script>
  import { defineComponent, reactive, toRefs } from 'vue'
  import { getConfigSet, ConfigSetSave } from '@/api/systemsetConfig'

  export default defineComponent({
    name: 'SystemsetConfig',
    setup() {
      const state = reactive({
        isData: false,
        from: {
          base: {},
          business: {},
        },
      })

      const saveConfigSet = async () => {
        state.listLoading = true
        await ConfigSetSave(state.from)
        state.listLoading = false
      }

      const fetchData = async () => {
        state.listLoading = true
        const { data } = await getConfigSet()
        state.from.base = Object.assign({}, data[0])
        state.from.business = Object.assign({}, data[1])
        state.isData = true
        state.listLoading = false
      }
      onMounted(() => {
        fetchData()
      })

      return {
        ...toRefs(state),
        fetchData,
        saveConfigSet,
      }
    },
  })
</script>
